package com.wander.consumer.controller;

import com.wander.api.service.ScheduleDubboService;
import com.wander.api.service.UserDubboService;
import com.wander.api.service.UserRestService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @author Wander.Zeng
 * @create 2018-02-06 14:02
 * @desc UserController
 */
public class Launcher4consumer {

    private static Logger logger = LoggerFactory.getLogger(Launcher4consumer.class);

    public static void main(String[] args) {
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("dubbo-consumer.xml");
        context.start();
        System.out.println("consumer start");

        // dubbo 协议
        try {
            UserDubboService userDubboService = context.getBean(UserDubboService.class);
            System.out.println(userDubboService.login("wander", "wander", 1L));

            ScheduleDubboService scheduleDubboService = context.getBean(ScheduleDubboService.class);
            System.out.println(scheduleDubboService.create("wander"));
        } catch (Exception e) {
            logger.error("dubbo 协议 error : " + e);
        }

        // rest 协议
        try {
            UserRestService userRestService = context.getBean(UserRestService.class);
            System.out.println(userRestService.login("www", "www", 5L));
        } catch (Exception e) {
            logger.error("rest 协议 error : " + e);
        }

        System.out.println("test");
    }

}
